<!-- 投标者 -->
<script setup>
import { ref,computed} from 'vue'
import {allbidder,delectBidder,editBidder} from '@/api/bidding.js'
import { ElMessage } from 'element-plus'
import {
    Edit,
    Delete
} from '@element-plus/icons-vue'

const BidderData = ref([])

// 分页状态
const currentPage = ref(1); // 当前页
const pageSize = ref(10);    // 每页显示的数据量

// 计算当前页展示的数据
const currentPageData = computed(() => {
  const start = (currentPage.value - 1) * pageSize.value;
  const end = start + pageSize.value;
  return BidderData.value.slice(start, end);
});

// 分页切换处理
const handlePageChange = (page) => {
  currentPage.value = page;
};

const show=async ()=>{
       let result=await allbidder();
       BidderData.value=result.data;
    }
show()

const handleReject=async (row)=>{
        // 处理打回操作
        await delectBidder(row.id);
        ElMessage.success("封号成功")
        show()
    }

const submitForm=async ()=>{
        // 处理编辑操作
       let result=await editBidder(formData.value)
       if(result.code===200){
        ElMessage.success('编辑成功')
        visibleDialog.value=false
       }else{
        ElMessage.error('编辑失败')
       }
        show()
    }

//控制弹窗是否显示
const visibleDialog = ref(false)
//添加表单数据模型
const formData = ref({
    id:'',
    name:'',
    contactEmail:'',
    address:'',
})

const editor=(row)=>{
    visibleDialog.value=true
    formData.value.name=row.name
    formData.value.contactEmail=row.contactEmail
    formData.value.address=row.address
    formData.value.id=row.id
}

</script>

<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>招标单位管理</span>
            </div>
        </template>
        <el-table :data="currentPageData" style="width: 100%">
            <el-table-column label="ID" prop="id"></el-table-column>
            <el-table-column label="招标单位" prop="name"></el-table-column>
            <el-table-column label="联系邮箱" prop="contactEmail"></el-table-column>
            <el-table-column label="地址"  prop="address"></el-table-column>
            <el-table-column label="注册日期" prop="registrationDate"></el-table-column>
            <el-table-column label="操作" width="150">
                <template #default="{ row }">
                    <el-button :icon="Edit" circle plain type="primary" @click="editor(row)"></el-button>
                    <el-button :icon="Delete" circle plain type="danger" @click="handleReject(row)"></el-button>
                </template>
            </el-table-column>
            <template #empty>
                <el-empty description="没有数据" />
            </template>
        </el-table>
                            <!-- 分页组件 -->
                            <el-pagination
                background
                layout="prev, pager, next"
                :total="BidderData.length"
                :current-page="currentPage"
                :page-size="pageSize"
                @current-change="handlePageChange" />
    </el-card>
    <!-- 弹窗 -->
    <el-dialog v-model="visibleDialog" title="招标单位信息编辑" width="20%">
    <!-- 表单容器 -->
    <el-form :model="formData" ref="formRef" label-width="120px">
      <el-form-item label="招标单位" prop="name">
        <el-input v-model="formData.name" placeholder="请输入投标单位名称" />
      </el-form-item>
      <el-form-item label="联系邮箱" prop="contactEmail">
        <el-input v-model="formData.contactEmail" placeholder="请输入联系邮箱" />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input v-model="formData.address" placeholder="请输入公司地址" />
      </el-form-item>
      <!-- 操作按钮 -->
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="closeDrawer">取消</el-button>
      </el-form-item>
    </el-form>
    </el-dialog>
</template>

<style lang="scss" scoped>
.page-container {
    min-height: 100%;
    width: 95%; /* 设置为宽一些 */
    max-width: 1500px; /* 最大宽度限制 */
    margin: 0 auto; /* 居中对齐 */
    box-sizing: border-box;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* 调整表格内边距和单元格宽度 */
.el-table {
    margin-top: 20px;
    padding: 10px;
}

.el-table-column {
    padding: 8px 10px;
}

</style>
